package com.lry.jvm.rtda.heap;

import com.lry.jvm.classfile.MemberInfo;
import com.lry.jvm.classfile.attributes.CodeAttribute;
import com.lry.jvm.classfile.attributes.ConstantValueAttribute;
import lombok.Data;

@Data
public class JField extends ClassMember{

    private int slotId;
    private int constValueIndex;

    public static JField[] newJFields(JClass jClass, MemberInfo[] fields) {
        JField[] jFields = new JField[fields.length];
        for(int i=0;i<fields.length;i++){
            jFields[i] = new JField();
            jFields[i].setJClass(jClass);
            jFields[i].copyMemberInfo(fields[i]);
            jFields[i].copyAttributes(fields[i]);
        }
        return jFields;
    }

    private void copyAttributes(MemberInfo field) {
        ConstantValueAttribute attr = field.constantValueAttribute();
        if(null!=attr){
            constValueIndex = attr.getConstantValueIndex();
        }
    }

}
